#pragma once
#include<iostream>
#include<assert.h>

using namespace std;

namespace zy
{
	class string
	{
	public:


		string& erase(size_t pos = 0, size_t len = npos);
		string& insert(size_t pos, const string& str);
		string& insert(size_t pos, const char s);
		string& append(const string& str);
		string substr(size_t pos = 0, size_t len = npos) const;
		
		

		typedef char* iterator;

		iterator begin()
		{
			return _str;
		}

		iterator end()
		{
			return _str+_size;
		}

		void swap(string& s);

		string(const char* str = "")
		{
			int len = strlen(str);
			_capacity = _size = len;
			_str = new char[_capacity + 1];
			strcpy(_str, str);
		}

		string(const string& s)
			:_str(nullptr)
		{
			string tmp(s._str);
			swap(tmp);
		}

		~string()
		{
			delete[]_str;
			_capacity = _size = 0;
		}

		char* c_str()const
		{
			return _str;
		}

		int size()const 
		{
			return _size;
		}

		int capacity()const
		{
			return _capacity;
		}

		void reserve(int n);
		
		string& operator +=(const string& s);
		string& operator +=(const char* str);
		string& operator = (const string& s);
		char operator[](int pos);
		char operator[](int pos)const;

		bool operator >(const string& s1)const;
		bool operator ==(const string& s1)const;
		bool operator >=(const string& s1)const;
		bool operator <(const string& s1)const;
		bool operator <=(const string& s1)const;
		bool operator !=(const string& s1)const;

		void clear()
		{
			erase(0);
		}

	private:
		char* _str;
		int _capacity;
		int _size;
		const static size_t npos = -1;
	};

	istream& operator >>(istream& in,string& s1);
	ostream& operator<<(ostream& out,const string& s);
}
